<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   站内短信
 */
defined('IN_YuLin') || exit('NO PERMIT!');

UserLogin(U($m.'/'.$c.'/'.$a));

$table = Table('article');
if($a == 'list')
{
	$data  = [];
	$where = ' FROM '.$table.' t WHERE t.cid = 3 AND status = 1';

	$page = max(1,intval($_GET['page']));
	$size = max(1,intval($_GET['size']));

	$tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
	if($tmp['p'])
	{
		$limit = ' LIMIT '.($page - 1) * $size.','.$size;
		
		$data = $db->getall('SELECT t.* '.$where.$orderby.$limit);
		foreach($data as $key => $val)
		{
			$val['dateline'] = date('Y/m/d H:i:s',$val['dateline']);
			
			$data[$key] = $val;
		}
	}
	echo json_encode(['pageIndex'=>$page,'pageSize'=>$size,'total'=>intval($tmp['p']),'rows'=>$data]);
	exit;
	$head['title'] = '网站公告';
	
	$tpl->display('member/notice');
}

if ($a == 'more'){
    $id = $_REQUEST['id'];
    if (!$id){
        echo '参数丢失';
        return;
    }
    $infoSql     = 'SELECT * FROM ' . $table . ' WHERE id = ' . $id;
    $articleInfo['content'] = htmlspecialchars_decode($articleInfo['content']);
    $articleInfo = $db->getrow($infoSql);
    $tpl->display('member/notice_more');
}

if($a == 'index'){
    // 查询所有站内公告， 默认分类1
$data  = array();
    $where = ' FROM '.$table.' t WHERE cid = 1';
    $tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
    if($tmp['p']){
        $page = max(1,intval($_GET['page']));
        $size = 20;
        $limit    = ' LIMIT '.($page - 1) * $size.','.$size;

        $orderby = ' ORDER BY t.id ASC ';
        $url = '?m='.$m.'&c='.$c.'&a='.$a;
        $data = $db->getall('SELECT t.* '.$where.$orderby.$limit);
        $multi = Multi($url,$page,$tmp['p'],$size);
    }
    $tpl->display('member/notice_main');
}

